﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class controls_urlLanguage : System.Web.UI.UserControl
{
    string selectedLanguage;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Language"] != null)
            {
                if (Session["Language"].ToString() == "th-TH")
                {
                    lbtTHLanguage.Visible = false;
                    lbtENLanguage.Visible = true;
                    imgLanguage.ImageUrl = "~/images/icon/lang_en.png";
                    imgLanguage.Attributes.Add("width", "19");
                    imgLanguage.Attributes.Add("height", "19");

                    lbtENLanguage.OnClientClick = "javascript:return confirm('" + Resources.CarInsurance.LanguageChangeMessage + "');";
                }
                else if (Session["Language"].ToString() == "en-US")
                {
                    lbtENLanguage.Visible = false;
                    lbtTHLanguage.Visible = true;
                    imgLanguage.ImageUrl = "~/images/icon/lang_th.png";
                    imgLanguage.Attributes.Add("width", "19");
                    imgLanguage.Attributes.Add("height", "19");

                    lbtTHLanguage.OnClientClick = "javascript:return confirm('" + Resources.CarInsurance.LanguageChangeMessage + "');";
                }
            }
        }
    }

    protected void btnLanguage_Click(object sender, EventArgs e)
    {
        selectedLanguage = string.Empty;

        if (lblLanguage.Text != string.Empty)
        {
            Session["Language"] = lblLanguage.Text;
        }

        if (Session["Language"] != null)
        {
            selectedLanguage = Session["Language"].ToString();
        }
        else
        {
            selectedLanguage = "th-TH";
            Session["Language"] = selectedLanguage;
        }

        if (selectedLanguage == "th-TH")
        {
            Session["Language"] = "en-US";
        }
        else
        {
            Session["Language"] = "th-TH";
        }

        lblLanguage.Text = selectedLanguage;

        Response.Redirect(Request.UrlReferrer.AbsoluteUri);

    }
}
